﻿namespace DA6502.CPU
{
    internal class InstructionAttribute : System.Attribute
    {
        /// <summary>
        /// 指令字节长
        /// </summary>
        public int Length;

        /// <summary>
        /// 是否为官方公开指令。
        /// </summary>
        public bool IsOfficial = true;

        /// <summary>
        /// 执行命令所需要的CPU时钟周期数
        /// </summary>
        public int Cycles;

        /// <summary>
        /// 分支处理时是否额外需要一个CPU时钟周期
        /// </summary>
        public bool HasAdditionalCycleOnBranch = false;

        /// <summary>
        /// 跨页处理时是否额外需要一个CPU时钟周期
        /// </summary>
        public bool HasAdditionalCycleOnPageCrossing = false;

        public InstructionAttribute(bool IsOfficial, int Length, int Cycles, bool HasAdditionalCycleOnPageCrossing, bool HasAdditionalCycleOnBranch)
        {
            this.IsOfficial = IsOfficial;
            this.Length = Length;
            this.Cycles = Cycles;
            this.HasAdditionalCycleOnBranch |= HasAdditionalCycleOnBranch;
            this.HasAdditionalCycleOnPageCrossing |= HasAdditionalCycleOnPageCrossing;
        }

        public InstructionAttribute(bool IsOfficial, int Length, int Cycles, bool HasAdditionalCyclesOnPageCrossing)
        {
            this.IsOfficial = IsOfficial;
            this.Length = Length;
            this.Cycles = Cycles;
            HasAdditionalCycleOnPageCrossing = HasAdditionalCyclesOnPageCrossing;
            HasAdditionalCycleOnBranch = false;
        }


        public InstructionAttribute(bool IsOfficial, int Length, int Cycles)
        {
            this.IsOfficial = IsOfficial;
            this.Length = Length;
            this.Cycles = Cycles;
            HasAdditionalCycleOnPageCrossing = false;
            HasAdditionalCycleOnBranch = false;
        }
    }
}